/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.controller;


import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import model.Dokument;
import model.Surat;

/**
 *
 * @author priska
 */
public class PengendaliPenerimaSuratDokument {
    public static ArrayList<Dokument>  datadokument = new ArrayList<>();
    public static ArrayList<Surat> datasurat = new ArrayList<>();
    
    public  static void tambahSurat(Surat surat){
        datasurat.add(surat);
    }
    public static void tambahDokument(Dokument dokumen){
        datadokument.add(dokumen);
    }
  public static String bacaDataSurat() {
        if (datasurat.isEmpty() == false) {
         String aa = new String();
            for (int i = 0; i < datasurat.size(); i++) {
                Surat cc = datasurat.get(i);
               aa += "Nomor Surat: " +cc.getNomorSurat()+ "Perihal: " + cc.getPerihal() + "Asal Surat:" + cc.getAsalSurat()
                        + "Penerima Surat:" + cc.getPenerimaSurat() + "Letak: "+ cc.getLetakSurat() +"Petugas Penerima Surat: "
                       + cc.getPetugasPenerimaSurat() + "Tanggal: " + cc.getTanggal();
            }
            return aa;
        } else {
            return "Kosong";
        } 
  }
   public static String bacaDataDokument() {
        if (datadokument.isEmpty() == false) {
            String dk = new String();
            for (int i = 0; i < datadokument.size(); i++) {
               Dokument doc = datadokument.get(i);
                dk += "Nomor: " + doc.getNoDokument() + " Perihal: " + doc.getPerihal()+ "Asal Surat: "+ doc.getAsalDokument()
                        + "Penerima Dokument:"+ doc.getPenerimaDokument()+ "Letak: "+doc.getLetakDokument()+ "Petugas Penerima:"
                        + doc.getPetugasPenerimaDokument() +"Tanggal: "+ doc.getTanggal();
            
        }
            return dk;
        }
            else {
            return "Kosong";
        }
  }
   public static void tambahtableSurat(Surat sr) throws SQLException {
        Connection con = model.Conection.open("jdbc:oracle:thin:@localhost:1521:XE", "hr", "sisil");
        Statement stat = con.createStatement();
        String sql = "insert into SURAT(NO_SURAT, PERIHAL, ASAL_SURAT, PENERIMA, LETAK_SURAT, PETUGAS_PENERIMA_SURAT, TANGGAL) values('"
                + sr.getNomorSurat() + "','" + sr.getPerihal() + "','"+ sr.getAsalSurat() +"','"+ sr.getPenerimaSurat() +"','"+ sr.getLetakSurat()
                + "','"+sr.getPetugasPenerimaSurat() +"','"+ sr.getTanggal()+"')";
               
        stat.executeUpdate(sql);
        con.close();
}
    public static void tambahtableDokument(Dokument doc) throws SQLException {
        Connection con = model.Conection.open("jdbc:oracle:thin:@localhost:1521:XE", "hr", "sisil");
        Statement stat = con.createStatement();
        String sql = "insert into DOKUMEN(NO_DOKUMEN, PERIHAL, ASAL_DOKUMEN, PENERIMA, LETAK_DOKUMEN, PETUGAS_PENERIMA_DOKUMEN, TANGGAL)values('"
                +doc.getNoDokument() + "','" + doc.getPerihal() + "','"+ doc.getAsalDokument() +"','"+ doc.getPenerimaDokument() +"','"+ doc.getLetakDokument()
                + "','"+doc.getPetugasPenerimaDokument() +"','"+ doc.getTanggal()+"')";
               
        stat.executeUpdate(sql);
        con.close();
}
 
    public static void simpanTabelSurat() throws SQLException {
        if (datasurat.isEmpty() == false) {
            Connection con = model.Conection.open("jdbc:oracle:thin:@localhost:1521:XE", "hr", "sisil");
            Statement stat = con.createStatement();
            int i = 0;
            while (i < datasurat.size()) {
                String sql = "insert into SURAT(NO_SURAT, PERIHAL, ASAL_SURAT, PENERIMA, LETAK_SURAT, PETUGAS_PENERIMA_SURAT, TANGGAL)values(" + datasurat.get(i).getNomorSurat()+ datasurat.get(i).getPerihal() + "','" + datasurat.get(i).getAsalSurat() + "','"+datasurat.get(i).getPenerimaSurat() +"','"+ datasurat.get(i).getLetakSurat() +"','"+ 
                 "','"+datasurat.get(i).getPetugasPenerimaSurat() +"','"+ datasurat.get(i).getTanggal()+"')";
                stat.executeUpdate(sql);
                i++;
            }
            con.close();
        }
    }
        public static void simpanTabelDokument() throws SQLException {
        if (datadokument.isEmpty() == false) {
            Connection con = model.Conection.open("jdbc:oracle:thin:@localhost:1521:XE", "hr", "sisil");
            Statement stat = con.createStatement();
            int i = 0;
            while (i < datadokument.size()) {
                String sql = "insert into DOKUMEN(NO_DOKUMEN, PERIHAL, ASAL_DOKUMEN, PENERIMA, LETAK_DOKUMEN, PETUGAS_PENERIMA_DOKUMEN, TANGGAL)values(" + datadokument.get(i).getNoDokument()+"','"+ datadokument.get(i).getPerihal() + "','" + datadokument.get(i).getAsalDokument() + "','"+datadokument.get(i).getPenerimaDokument() +"','"+ datadokument.get(i).getLetakDokument() +"','"+ 
                 "','"+datadokument.get(i).getPetugasPenerimaDokument() +"','"+ datadokument.get(i).getTanggal()+"')";
                stat.executeUpdate(sql);
                i++;
            }
            con.close();
        }
}
}

    

